package com.zt.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zt.service.EmployeeService;
import com.zt.utils.Query;
import com.zt.utils.Result;
import org.example.systemset_pojo.Employee;
import org.example.systemset_pojo.Store;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;


    @RequestMapping("/selectpage")
    public Result selectPage(Query query){
        Page<Employee> page1 = employeeService.selectpage(query);
        return Result.OK(page1);
    }

    @RequestMapping("/del")
    public Result del(Integer id){
        boolean b = employeeService.removeById(id);
        if(b){
            return Result.OK();
        }
        return Result.ERROR();
    }


    @RequestMapping("/getmendian")
    public Result getmendian(){
        List<Store> employee = employeeService.glist();
        return Result.OK(employee);
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Employee employee){
        boolean b = employeeService.save(employee);
        if(b){
            return Result.OK();
        }
        return Result.ERROR();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Employee employee){
        boolean b = employeeService.updateById(employee);
        if(b){
            return Result.OK();
        }
        return Result.ERROR();
    }

}
